extends ../_layout
block content
   div.container(style='width: 400px; margin: 160px auto;')
      h1= message
      form.well(method="post")
         h1 Update Profile

         input(type='hidden', name='_csrf', value='#{csrf}')

         div.input-group
            span.input-group-addon= 'First Name:'
            input.form-control(type='text', name='firstname', data-validation='least_one_char', value= profile.firstname)

         div.input-group
            span.input-group-addon= 'Last Name: '
            input.form-control(type='text', name='lastname', data-validation='least_one_char', value= profile.lastname)

         if(user && user.role && user.role == 'admin')
            div.input-group
               span.input-group-addon= 'Role: '
               select.form-control(name='role', value=profile.role)
                  - opts = ['member', 'official', 'manager', 'admin'];
                  - each o in opts
                     option(selected= (profile.role==o)) #{o}
         else
            input(type='hidden', name='role', value='#{profile.role}')


         div.input-group(style='width: 100%;')
            button.btn.btn-primary.form-control(type="submit")
               i.icon-lock.icon-white Update

         hr
         ol.breadcrumb
            li: a(href='/users/profile/' + profile._id) Back


   //script(src='/js/jquery.min.js')
   //script(src='/js/bootstrap.min.js')
   script(src='/js/form-validator/jquery.form-validator.min.js')
   script.
      $.formUtils.addValidator({
         name: 'least_one_char',
         validatorFunction: function(value, $el, config, language, $form){
            return /^(?=.*[a-zA-Z]).{1,20}$/i.test(value);
         },
         errorMessage: 'The input has to be an alphabet value between 1-20 characters',
         errorMessageKey: 'badLetter'
      });
      $.formUtils.addValidator({
         name: 'my_password',
         validatorFunction: function(value, $el, config, language, $form){
            return /^(?=.*[a-zA-Z])(?=.*[0-9]).{4,20}$/i.test(value);
         },
         errorMessage: 'The password should consists of at least 1 letter and at least 1 number and between 4-20 characters',
         errorMessageKey: 'badPassword'
      });

      $(document).ready(function(){
         $.validate();
      });

